<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{call}</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.builtin.functions.html" title="Chapter 7. Built-in Functions">
<link rel="prev" href="language.function.block.html" title="{block}">
<link rel="next" href="language.function.capture.html" title="{capture}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{call}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.block.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Built-in Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.capture.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{call}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.call"></a>{call}</h2></div></div></div>
<p>
  <code class="varname">{call}</code> is used to call a template function defined by the
  <a class="link" href="language.function.function.html" title="{function}"><code class="varname">{function}</code></a>
  tag just like a plugin function. 
  </p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
   Template functions are defined global. Since the Smarty compiler is a single-pass compiler,
   The <a class="link" href="language.function.call.html" title="{call}"><code class="varname">{call}</code></a>
   tag must be used to call a template function defined externally from the given template. 
   Otherwise you can directly use the function as <code class="literal">{funcname ...}</code> in the template.
  </p>
</div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
  The <code class="varname">{call}</code> tag must have the  <em class="parameter"><code>name</code></em> attribute
  which contains the the name of the template function.
  </p></li>
<li class="listitem"><p>
  Values for variables can be passed to the template function as
  <a class="link" href="language.syntax.attributes.html" title="Attributes">attributes</a>.
 </p></li>
</ul></div>
<p><span class="bold"><strong>Attributes:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">name</td>
<td align="center">string</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the template function</td>
</tr>
<tr>
<td align="center">assign</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the variable that the output of
        called template function will be assigned to</td>
</tr>
<tr>
<td align="center">[var ...]</td>
<td align="center">[var type]</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>variable to pass local to template function</td>
</tr>
</tbody>
</table></div>
<p><span class="bold"><strong>Option Flags:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Name</th>
<th>Description</th>
</tr></thead>
<tbody><tr>
<td align="center">nocache</td>
<td>Call the template function in nocache mode</td>
</tr></tbody>
</table></div>
<div class="example">
<a name="id367817"></a><p class="title"><b>Example 7.20. Calling a recursive menu example</b></p>
<div class="example-contents">
<pre class="programlisting">

{* define the function *}
{function name=menu level=0}
  &lt;ul class="level{$level}"&gt;
  {foreach $data as $entry}
    {if is_array($entry)}
      &lt;li&gt;{$entry@key}&lt;/li&gt;
      {call name=menu data=$entry level=$level+1}
    {else}
      &lt;li&gt;{$entry}&lt;/li&gt;
    {/if}
  {/foreach}
  &lt;/ul&gt;
{/function}

{* create an array to demonstrate *}
{$menu = ['item1','item2','item3' =&gt; ['item3-1','item3-2','item3-3' =&gt;
['item3-3-1','item3-3-2']],'item4']}

{* run the array through the function *}
{call name=menu data=$menu}
{call menu data=$menu} {* short-hand *}

  </pre>
<p>
  Will generate the following output
 </p>
<pre class="programlisting">

* item1
* item2
* item3
      o item3-1
      o item3-2
      o item3-3
            + item3-3-1
            + item3-3-2
* item4

  </pre>
</div>
</div>
<br class="example-break"><p>
  See also
  <a class="link" href="language.function.function.html" title="{function}"><code class="varname">{function}</code></a>
 </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.block.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.builtin.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.capture.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{block} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {capture}</td>
</tr>
</table>
</div>
</body>
</html>
